/* Copyright (C) 2010 Fredrique Samuels, fredriquesamuels@gmail.com 

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

//Include library header

#include "uistyle.h"

namespace tri{
namespace ui{

extUIStyle::extUIStyle(){}
extUIStyle::~extUIStyle(){}

void extUIStyle::loadComponentStyle(tri::ui::extStyle* style){
	style->setBGImage(tri::sys::formatPathString("data\\ui\\win7\\win7_raised.png"));
	style->setSegmentInsets(3,3,3,3);
	style->setImageInsets(3,3,3,3);
	style->setColor(255,255,255,255);
}

void extUIStyle::loadPanelStyle(tri::ui::extStyle* style){
	style->setBGImage(tri::sys::formatPathString("data\\ui\\win7\\win7_pane.png"));
	style->setSegmentInsets(3,3,3,3);
	style->setImageInsets(3,3,3,3);
	style->setColor(255,255,255,200);
//	style->setInsets(3,3,3,3);
}

void extUIStyle::loadFontStyle(tri::ui::extStyle* style){
	style->setTextColor(0,0,0,255);
	style->setTextBGColor(0,0,0,0);
	style->setCharacterHeight(12);
	style->setTextAlignment(tri::ui::ALIGN_CENTER);
	style->setFontSize(40);
	style->setFont("times.ttf");
	
	style->setTextColor(100,100,100,255,tri::DISABLED);
}

void extUIStyle::loadLabelStyle(tri::ui::extStyle* style){
	style->setColor(0,0,0,0);
//	style->setInsets(3,3,3,3);
	loadFontStyle(style);
}

void extUIStyle::loadButtonStyle(tri::ui::extStyle* style){
	style->setBGImage(tri::sys::formatPathString("data\\ui\\win7\\win7_button.png"));
	style->setSegmentInsets(3,3,3,3);
	style->setImageInsets(3,3,3,3);
	style->setInsets(3,3,3,3);
	style->setColor(161,179,252,255,tri::BUTTON_PRESSED);
	style->setColor(211,229,252,255,tri::MOUSE_OVER);
	style->setColor(186,204,252,255,tri::FOCUS);
	style->setColor(200,200,200,255,tri::DISABLED);
	loadFontStyle(style);
}

void extUIStyle::loadTextEditStyle(tri::ui::extStyle* style){
	style->setBGImage(tri::sys::formatPathString("data\\ui\\win7\\win7_textedit.png"));
	style->setSegmentInsets(3,3,3,3);
	style->setImageInsets(3,3,3,3);
	style->setInsets(3,3,3,3);
	style->setColor(255,255,255,255);
	loadFontStyle(style);
	style->setTextColor(255,255,255,255,tri::FOCUS);
	style->setTextBGColor(51,153,255,255,tri::FOCUS);
	style->setTextAlignment(ALIGN_LEFT);
}

void extUIStyle::loadNumberEditStyle(tri::ui::extStyle* style){
	style->setBGImage(tri::sys::formatPathString("data\\ui\\win7\\win7_textedit.png"));
	style->setSegmentInsets(3,3,3,3);
	style->setImageInsets(3,3,3,3);
	style->setInsets(3,3,3,3);
	style->setColor(255,255,255,255);
	loadFontStyle(style);
	style->setTextColor(255,255,255,255,tri::FOCUS);
	style->setTextBGColor(51,153,255,255,tri::FOCUS);
	style->setTextAlignment(ALIGN_LEFT);
}

void extUIStyle::loadCheckBoxStyle(tri::ui::extStyle* style){
	style->setBGImage(tri::sys::formatPathString("data\\ui\\win7\\win7_check_box.png"));
	style->setBGImage(tri::sys::formatPathString("data\\ui\\win7\\win7_check_box_checked.png"),tri::CHECKED);
	style->setSegmentInsets(0,0,0,0);
	style->setImageInsets(0,0,0,0);
	style->setInsets(14,0,0,0);
	loadFontStyle(style);
}

void extUIStyle::loadHSliderStyle(tri::ui::extStyle* style){
	style->setBGImage(tri::sys::formatPathString("data\\ui\\win7\\win7_slider_track2_hor.png"));
	style->setSegmentInsets(2,0,0,0);
	style->setImageInsets(2,0,0,0);
}

void extUIStyle::loadHSliderButtonStyle(tri::ui::extStyle* style){
	style->setBGImage(tri::sys::formatPathString("data\\ui\\win7\\win7_sliderh_button.png"));
	style->setColor(161,179,252,255,tri::BUTTON_PRESSED);
	style->setColor(161,179,252,155,tri::MOUSE_DRAG);
	style->setColor(211,229,252,255,tri::MOUSE_OVER);
	style->setColor(161,179,252,255,tri::FOCUS);
}

void extUIStyle::loadVSliderStyle(tri::ui::extStyle* style){
	style->setBGImage(tri::sys::formatPathString("data\\ui\\win7\\win7_slider_track2_ver.png"));
	style->setSegmentInsets(2,0,0,0);
	style->setImageInsets(2,0,0,0);
}

void extUIStyle::loadVSliderButtonStyle(tri::ui::extStyle* style){
	style->setBGImage(tri::sys::formatPathString("data\\ui\\win7\\win7_sliderv_button.png"));
	style->setColor(161,179,252,255,tri::BUTTON_PRESSED);
	style->setColor(161,179,252,155,tri::MOUSE_DRAG);
	style->setColor(211,229,252,255,tri::MOUSE_OVER);
	style->setColor(161,179,252,255,tri::FOCUS);
}

void extUIStyle::loadScrollPanelStyle(tri::ui::extStyle* style){
	style->setBGImage(tri::sys::formatPathString("data\\ui\\win7\\win7_sunken.png"));
	style->setSegmentInsets(2,2,2,2);
	style->setImageInsets(2,2,2,2);
	style->setColor(255,255,255,200);
//	style->setInsets(1,1,1,1);
}

void extUIStyle::loadScrollPanelVerticalSliderStyle(tri::ui::extStyle* style){
	style->setBGImage(tri::sys::formatPathString("data\\ui\\win7\\win7_slider_track_vert.png"));
	style->setSegmentInsets(0,2,0,2);
	style->setImageInsets(0,2,0,2);
}

void extUIStyle::loadScrollPanelVerticalSliderThumbButtonStyle(tri::ui::extStyle* style){
	style->setBGImage(tri::sys::formatPathString("data\\ui\\win7\\win7_sliderv_button.png"));
	style->setSegmentInsets(2,2,2,2);
	style->setImageInsets(2,2,2,2);
	style->setColor(161,179,252,255,tri::BUTTON_PRESSED);
	style->setColor(161,179,252,155,tri::MOUSE_DRAG);
	style->setColor(211,229,252,255,tri::MOUSE_OVER);
	style->setColor(161,179,252,255,tri::FOCUS);
}

void extUIStyle::loadScrollPanelHorizontalSliderStyle(tri::ui::extStyle* style){
	style->setBGImage(tri::sys::formatPathString("data\\ui\\win7\\win7_slider_track_hor.png"));
	style->setSegmentInsets(2,0,2,0);
	style->setImageInsets(2,0,2,0);
}

void extUIStyle::loadScrollPanelHorizontalSliderThumbButtonStyle(tri::ui::extStyle* style){
	style->setBGImage(tri::sys::formatPathString("data\\ui\\win7\\win7_sliderh_button.png"));
	style->setSegmentInsets(2,2,2,2);
	style->setImageInsets(2,2,2,2);
	style->setColor(161,179,252,255,tri::BUTTON_PRESSED);
	style->setColor(161,179,252,155,tri::MOUSE_DRAG);
	style->setColor(211,229,252,255,tri::MOUSE_OVER);
	style->setColor(161,179,252,255,tri::FOCUS);
}

void extUIStyle::loadTabBackPanelStyle(tri::ui::extStyle* style){
	style->setColor(0,0,0,0);
}

void extUIStyle::loadTabButtonStyle(tri::ui::extStyle* style){
	style->setBGImage(tri::sys::formatPathString("data\\ui\\win7\\win7_tabbutton.png"));
	style->setSegmentInsets(2,6,7,2);
	style->setImageInsets(2,6,7,2);
	style->setInsets(3,3,4,3);
	style->setColor(211,229,252,255,tri::BUTTON_PRESSED);
	style->setColor(191,209,232,255,tri::CHECKED);
	loadFontStyle(style);
}

void extUIStyle::loadListItemStyle(tri::ui::extStyle* style){
	style->setSegmentInsets(3,3,3,3);
	style->setImageInsets(3,3,3,3);
	style->setInsets(3,3,3,3);
	style->setColor(0,0,0,0);
	style->setColor(161,179,252,255,tri::BUTTON_PRESSED);
	style->setColor(211,229,252,255,tri::MOUSE_OVER);
	style->setColor(186,204,252,255,tri::FOCUS);
	loadFontStyle(style);
	style->setTextAlignment(ALIGN_LEFT);
}

void extUIStyle::loadSpinBoxNumberEditStyle(tri::ui::extStyle* style){
	loadTextEditStyle(style);
}

void extUIStyle::loadSpinBoxUpButtonStyle(tri::ui::extStyle* style){
	style->setBGImage(tri::sys::formatPathString("data\\ui\\win7\\spin_up.png"));
	style->setSegmentInsets(2,2,2,2);
	style->setImageInsets(2,2,2,2);
	style->setInsets(2,2,2,2);
	style->setColor(161,179,252,255,tri::BUTTON_PRESSED);
	style->setColor(211,229,252,255,tri::MOUSE_OVER);
	style->setColor(186,204,252,255,tri::FOCUS);
	loadFontStyle(style);
}

void extUIStyle::loadSpinBoxDownButtonStyle(tri::ui::extStyle* style){
	style->setBGImage(tri::sys::formatPathString("data\\ui\\win7\\spin_down.png"));
	style->setSegmentInsets(2,2,2,2);
	style->setImageInsets(2,2,2,2);
	style->setInsets(2,2,2,2);
	style->setColor(161,179,252,255,tri::BUTTON_PRESSED);
	style->setColor(211,229,252,255,tri::MOUSE_OVER);
	style->setColor(186,204,252,255,tri::FOCUS);
	loadFontStyle(style);
}

void applyUIStyle(extUIStyle* uiStyle){
	if(uiStyle==NULL){
		return;
	}
	tri::ui::extStyle* style = NULL;
	std::string style_name;
	
	style_name = "DefaultComponentStyle";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadComponentStyle(style);
	
	style_name = "DefaultPanelStyle";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadPanelStyle(style);
	
	style_name = "DefaultLabelStyle";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadLabelStyle(style);
	
	style_name = "DefaultButtonStyle";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadButtonStyle(style);
	
	style_name = "DefaultTextEditStyle";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadTextEditStyle(style);
	
	style_name = "DefaultNumberEditStyle";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadTextEditStyle(style);
	
	style_name = "DefaultCheckBoxStyle";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadCheckBoxStyle(style);
	
	style_name = "DefaultHSliderBarStyle";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadHSliderStyle(style);
	
	style_name = "DefaultHSliderBarStyle.ThumbButton";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadHSliderButtonStyle(style);
	
	style_name = "DefaultVSliderBarStyle";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadVSliderStyle(style);
	
	style_name = "DefaultVSliderBarStyle.ThumbButton";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadVSliderButtonStyle(style);
	
	style_name = "DefaultScrollPanelStyle";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadScrollPanelStyle(style);
	
	style_name = "DefaultScrollPanelStyle";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadScrollPanelStyle(style);
	
	style_name = "DefaultScrollPanelStyle.ContentPanel";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadPanelStyle(style);
	
	style_name = "DefaultScrollPanelStyle.VerticalSlider";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadScrollPanelVerticalSliderStyle(style);
	
	style_name = "DefaultScrollPanelStyle.VerticalSlider.ThumbButton";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadScrollPanelVerticalSliderThumbButtonStyle(style);
	
	style_name = "DefaultScrollPanelStyle.HorizontalSlider";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadScrollPanelHorizontalSliderStyle(style);
	
	style_name = "DefaultScrollPanelStyle.HorizontalSlider.ThumbButton";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadScrollPanelHorizontalSliderThumbButtonStyle(style);
	
	style_name = "DefaultTabPanelStyle.ButtonPanel";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadTabBackPanelStyle(style);
	
	style_name = "DefaultTabPanelStyle.ButtonPanel.TabButton";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadTabButtonStyle(style);
	
	style_name = "DefaultItemListStyle";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadPanelStyle(style);
	
	style_name = "DefaultItemListStyle.ListItem";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadListItemStyle(style);
	
	
	style_name = "DefaultSpinBoxStyle.NumberEdit";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadSpinBoxNumberEditStyle(style);
	
	
	style_name = "DefaultSpinBoxStyle.DownButton";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadSpinBoxDownButtonStyle(style);
	
	style_name = "DefaultSpinBoxStyle.UpButton";
	tri::ui::extStyle::createStyle(style_name);
	style = tri::ui::extStyle::getStyle(style_name);
	style->clear();
	uiStyle->loadSpinBoxUpButtonStyle(style);

}


void loadWin7StyleAsDefault(){
	extUIStyle uiStyle;
	applyUIStyle(&uiStyle);
}

}
}